package com.itts.hk.theard.Demo;


import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 多线程测试类
 * @author ouyangjun
 */
public class ThreadPool {

    /**
     * 默认的线程池,指定线程池默认大小,也可以指定具体的线程池,如上面的注释代码
     * Executors.newCachedThreadPool();        //创建一个缓冲池，缓冲池容量大小为Integer.MAX_VALUE
     * Executors.newSingleThreadExecutor();    //创建容量为1的缓冲池
     * Executors.newFixedThreadPool(int);      //创建固定容量大小的缓冲池
     */
    private ThreadPoolExecutor poolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(5);

    public static void main(String args[]) {
        // 执行测试方法
        new ThreadPool().exec();
    }

    public void exec() {
        /*List<Object> list = new ArrayList<Object>();
        list.add("oysept111111");
        list.add(222222);
        list.add(333333);
        list.add(444444);
        ListThread listThread = new ListThread(list);

        Map<String, Object> map = new HashMap<>();
        map.put("555555", "oysept111111");
        map.put("666666", 222222);
        map.put("777777", 333333);
        map.put("888888", 444444);
        //MapThread mapThread = new MapThread(map);

        // 执行
        Future<String> resQingStor = poolExecutor.submit(listThread); // 提交多线程任务
        //Future<String> resRemedy = poolExecutor.submit(mapThread); // 提交多线程任务
        try {
            String listStr = resQingStor.get(); // 获取线程方法的返回值
            //String mapStr = resRemedy.get(); // 获取线程方法的返回值
            //System.out.println("==>ThreadPoolExecutor处理成功!,listStr="+listStr+",mapStr="+mapStr);
        } catch (InterruptedException e) {
            System.out.println("InterruptedException异常: "+e);
        } catch (ExecutionException e) {
            System.out.println("ExecutionException异常: "+e);
        }*/
        //120.324175:31.504608, 120.324647:31.504342,  120.324835:31.505289
        List<Point2D.Double> list= new ArrayList<Point2D.Double>();
        double px = 120.324175;
        double py = 31.504608;
        double px1 = 120.324647;
        double py1 = 31.504342;
        double px2 = 120.324835;
        double py2 = 31.505289;
        Point2D.Double aDouble = new Point2D.Double(px, py);
        Point2D.Double aDouble1 = new Point2D.Double(px1, py1);
        Point2D.Double aDouble2 = new Point2D.Double(px2, py2);
        list.add(aDouble);
        list.add(aDouble1);
        list.add(aDouble2);

        //120.323858:31.505061,120.323837:31.503876,120.325773:31.504361
        List<Point2D.Double> lists= new ArrayList<Point2D.Double>();//区域范围
        Point2D.Double a1 = new Point2D.Double(120.323858, 31.505061);
        Point2D.Double a2 = new Point2D.Double(120.323837, 31.503876);
        Point2D.Double a3 = new Point2D.Double(120.325773, 31.504361);
        lists.add(a1);
        lists.add(a2);
        lists.add(a3);

        MapThread mapThread = new MapThread(lists,list);
        Future<String> future = poolExecutor.submit(mapThread);

        try {
            String s = future.get();
            System.out.println("测试"+s);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
